package com.xbongbong.formula.qlexpress.operator.math;

import com.ql.util.express.Operator;
import com.ql.util.express.OperatorOfNumber;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.MathUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.enums.ErrorCodeEnum;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/7/4 17:18
 * @desrcption: 返回将参数 number 向上舍入（沿绝对值增大的方向）为最接近的指定基数的倍数。
 */
public class OperatorCeiling extends Operator {

    public OperatorCeiling(String name){
        this.name = name;
    }

    public OperatorCeiling(String aliasName, String aName, String errorInfo){
        this.aliasName = aliasName;
        this.name = aName;
        this.errorInfo = errorInfo;
    }

    @Override
    public Object executeInner(Object[] list) throws Exception {
        Integer cardinality = Integer.valueOf(String.valueOf(list[1]));
        if (Objects.equals(cardinality, 0)) {
            return 0;
        }
        Number divide = OperatorOfNumber.divide(list[0], list[1], true);
        return OperatorOfNumber.multiply(cardinality , MathUtil.ceil(Math.ceil(divide.doubleValue()), 0), true);


    }
}
